package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;


/**
 * <p>
 * Assignment实体，所有分派对象的基类，代表着任务的分派。
 * </p>
 * 
 */
@Entity()
//@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "T_ASSIGNMENTS")
@BatchSize(size = 20)
@Lazy(value = true)
//@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Assignment extends BasicModel {
	
	public final static int ASSNTYPE_DEVICE = 0;     // 设备
	public final static int ASSNTYPE_WORKCENTER = 1; // 工作中心
	public final static int ASSNTYPE_TOOL = 2;       // 工具
	
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name = "UNIQUEID", unique = true)
	protected String uniqueId;
	
	@Column(name = "TASKUID")
	protected String operationTaskUid;
//	// many-to-one
//	@ForeignKey(name = "null")
//	@ManyToOne(fetch = FetchType.LAZY)
//	@JoinColumn(name = "TASKUID", insertable = false, updatable = false)
//	protected OperationTask operationTask;
	
	//分派的员工
	@Column(name = "EMPLOYEEID")
	protected String employeeUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "EMPLOYEEID", insertable = false, updatable = false)
	protected Employee employee;


	/**
	 * 类型与状态映射--assntype
	 */
	@Column(name = "ASSNTYPE")
	protected String assnType;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'assntype'", referencedColumnName = "TYPESNAME")) })
	protected TypesData assnTypeDesc;

	@Column(name = "ASSNSTART")
	protected Date assnStart;
	@Column(name = "ASSNFINISH")
	protected Date assnFinish;
	@Column(name = "ASSNQTY")
	protected Double assnQty;
	
	/**
	 * 分派单元数，可以为百分比
	 */
	@Column(name = "ASSNUNITS")
	protected Double assnUnits;
	/**
	 * 类型与状态映射--assnstate
	 */
	@Column(name = "ASSNSTATE")
	protected Long assnState;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'assnstate'", referencedColumnName = "TYPESNAME")) })
	protected TypesData assnStateDesc;
	
	/**
	 * 是否有效
	 */
	@Column(name = "ISINEFFECT")
	protected Boolean effective;
	


	/**
	 * 空的构造函数
	 */
	public Assignment() {
	}
	
	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getUniqueId();
	}
	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setUniqueId(uuid);
	}

	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}


	/**
	 * 获取任务Uid
	 * @return
	 */
	
	public String getOperationTaskUid() {
		return operationTaskUid;
	}

	/**
	 * 设置任务Uid
	 * @param operationTaskUid
	 */
	public void setOperationTaskUid(String operationTaskUid) {
		this.operationTaskUid = operationTaskUid;
	}

	/**
	 * 获取工人Uid
	 * @return
	 */
	
	public String getEmployeeUid() {
		return employeeUid;
	}

	/**
	 * 设置工人Uid
	 * @param employeeUid
	 */
	public void setEmployeeUid(String employeeUid) {
		this.employeeUid = employeeUid;
	}

	/**
	 * 获取工人对象
	 * @return
	 */
	
	public Employee getEmployee() {
		return employee;
	}

	/**
	 * 设置工人对象
	 * @param employee
	 */
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

//	public OperationTask getOperationTask() {
//		return operationTask;
//	}
//
//	public void setOperationTask(OperationTask operationTask) {
//		this.operationTask = operationTask;
//	}

	public Double getAssnUnits() {
		return assnUnits;
	}

	public void setAssnUnits(Double assnUnits) {
		this.assnUnits = assnUnits;
	}

	public String getAssnType() {
		return assnType;
	}

	public void setAssnType(String assnType) {
		this.assnType = assnType;
	}

	public TypesData getAssnTypeDesc() {
		return assnTypeDesc;
	}

	public void setAssnTypeDesc(TypesData assnTypeDesc) {
		this.assnTypeDesc = assnTypeDesc;
	}

	public Date getAssnStart() {
		return assnStart;
	}

	public void setAssnStart(Date assnStart) {
		this.assnStart = assnStart;
	}

	public Date getAssnFinish() {
		return assnFinish;
	}

	public void setAssnFinish(Date assnFinish) {
		this.assnFinish = assnFinish;
	}

	public Double getAssnQty() {
		return assnQty;
	}

	public void setAssnQty(Double assnQty) {
		this.assnQty = assnQty;
	}

	public Long getAssnState() {
		return assnState;
	}

	public void setAssnState(Long assnState) {
		this.assnState = assnState;
	}

	public TypesData getAssnStateDesc() {
		return assnStateDesc;
	}

	public void setAssnStateDesc(TypesData assnStateDesc) {
		this.assnStateDesc = assnStateDesc;
	}

	public Boolean getEffective() {
		return effective;
	}
	public void setEffective(Boolean effective) {
		this.effective = effective;
	}
	
	
}